package cn.dgiot.fd;

import cn.dgiot.fd.model.ThingModel;
import cn.dgiot.fd.service.IAmqpClientService;
import cn.dgiot.fd.service.IMessageService;
import cn.dgiot.fd.service.IThingModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * [阿里云初始化]
 * @author
 *
 */
@Component
public class AliyunInit implements ApplicationListener<ContextRefreshedEvent> {
	
	@Autowired
	private IAmqpClientService amqpClientService;

	@Autowired
	private IMessageService messageService;
	
	@Autowired
	private IThingModelService thingModelService;
	
	public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {

		try {
			thingModelService.refreshDefaultThingModel(new ThingModel());
			
			messageService.messageInit();
			
			amqpClientService.createAmqpClient();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
